<head>
  <title>UCD APP V1.0
</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  <script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAwbkbZLyhsmTCWXbTcjbgbRSzHs7K5SvaUdm8ua-Xxy_-2dYwMxQMhnagaawTo7L1FE1-amhuQxIlXw"></script>
  <script type="text/javascript">

  var ge;
  var la;
  var latitude;
  var longitude;
  var heading;
  var buildings;
  var turning;
  var frameendEL;
  var kmzs;
  var nls;

  google.load("earth", "1");

  function init() {
    google.earth.createInstance('map3d', initCB, failureCB);
  }
  
  function initCB(instance) {
    ge = instance;
    ge.getWindow().setVisibility(true);
  
    frameendEL = false;
    buildings = false;
  
   
    toggleBuildings();
    ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
    
    ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
   // ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
    ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN,true);

    la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
    var win = ge.getWindow();
    create3dModel();

    

  }
  function toggleBuildings(){
  if (!buildings)
  {
  buildings = true;
  //toggleVisibilityNLs(false);
  ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, buildings);

  }
  else
  {
  buildings = false;
  toggleVisibilityNLs(true);
  ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, buildings);
  }
  }
    function loadKmz(kmzFile){
  
  var networkLink = ge.createNetworkLink("");
  networkLink.setName("Opened KMZ File");
  networkLink.setFlyToView(false);  
  var link = ge.createLink("");
  link.setHref(kmzFile);
  networkLink.setLink(link);
  networkLink.setVisibility(true);
  ge.getFeatures().appendChild(networkLink);
  nls.push(networkLink);



return networkLink;
  }
  function toggleVisibilityNLs(visibility){
  var nl;
  for (var x=0; x<6; x+=1){
  
  nls[x].setVisibility(visibility);
  
  }
  
  }

  function failureCB() { 

  }
  function createPlacemark(lat,lng){
  var placemark = ge.createPlacemark('');
  var point = ge.createPoint('');
  point.setLatitude(lat);
  point.setLongitude(lng);
  placemark.setGeometry(point);
  ge.getFeatures().appendChild(placemark);
  }
  function za(lat,lng,head,range,altitude,tilt){
    turning = false;
    latitude = lat;
    longitude = lng;
    heading = head;
    la.set(lat,lng,0,ge.ALTITUDE_RELATIVE_TO_GROUND,heading,tilt,range);
    if (!frameendEL){
    toggleFrameendEL();
    }
    ge.getOptions().setFlyToSpeed(.25);
    ge.getView().setAbstractView(la);
    turning = false;
 
    }
  
  function toggleFrameendEL(){
  if (!frameendEL){
  window.google.earth.addEventListener(ge, 'frameend', zoomAround);
  frameendEL = true;
   
  }else{
  google.earth.removeEventListener(ge, 'frameend', zoomAround);
  frameendEL = false;
  
  }
  
  }
  function zoomAround(){
              
    latemp = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);

    
 }
  
 /* function turn(){
   ge.getOptions().setFlyToSpeed(1000);
    heading+=.5;
    if (heading > 360){
    heading -= 360;}   

    la.setHeading(heading);
    la.setLatitude(latitude);
    la.setLongitude(longitude);
    ge.getView().setAbstractView(la);    
  }*/
  
function create3dModel() {
//get the current camera location
var lookAt = ge.getView().copyAsLookAt
(ge.ALTITUDE_RELATIVE_TO_GROUND);

// create the model geometry
var model = ge.createModel('');

// set up the model's location
var loc = ge.createLocation('');
loc.setLatitude( 53.3093);
loc.setLongitude( -6.2244);
model.setLocation(loc);

// set up the model's link (must be a COLLADA file).
// this model was created in SketchUp
var link = ge.createLink('');
model.setLink(link);
link.setHref('https://leiucd.googlecode.com/svn/trunk/'+'csi.dae');

// create the model placemark and add it to Earth
var modelPlacemark = ge.createPlacemark('');
modelPlacemark.setGeometry(model);
ge.getFeatures().appendChild(modelPlacemark);

// zoom in on the model
//lookAt.setRange(300);
//lookAt.setTilt(80);
//ge.getView().setAbstractView(lookAt);

// persist the placemark for other interactive samples
window.placemark = modelPlacemark;

} 

 
  function buttonClick(lat,lng,head,range,altitude,tilt) {
    za(lat,lng,head,range,altitude,tilt); 
    

  }
  function stopFly() {
    if(frameendEL){
      toggleFrameendEL();
    }
    ge.getOptions().setFlyToSpeed(1);
    turning = false;
  }

 
  </script>
</head>
  <body onload='init()' id='body'>
    <table width='725px' cellspacing='6'>
    <tr>
      <td valign=top>
      <div id='map3d' style='border: 1px solid silver; height: 500px; width: 725px;'></div>
      </td><td>      <br/>
      
</td>
   </tr>

     <tr align=center>
	<td valign=top>

      <input type="button" onclick="buttonClick(53.307632,-6.221766,0,700,0,10)" value="UCD"/>
     
            <input type="button" onclick="buttonClick(53.309246, -6.223991,0,100,0,60)" value="CSI"/>
            
            
       </td>
    </tr>
  </table>


</body>
</html>
